import turtle
import time


# 数码管间隔
def drawGap():
    turtle.penup()
    turtle.fd(5)


# 单段数码管
def drawLine(draw):
    drawGap()
    # 如果此数字有这条数码管就放下笔，反之就拿起笔
    turtle.pendown() if draw else turtle.penup()
    # 移动40px
    turtle.fd(40)
    drawGap()
    # 下一次笔的方向
    turtle.right(90)


# 根据数字绘制七段数码管
def drawDigit(d):
    drawLine(True) if d in [2, 3, 4, 5, 6, 8, 9] else drawLine(False)
    drawLine(True) if d in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine(False)
    drawLine(True) if d in [0, 2, 3, 5, 6, 8] else drawLine(False)
    drawLine(True) if d in [0, 2, 6, 8] else drawLine(False)
    turtle.left(90)
    drawLine(True) if d in [0, 4, 5, 6, 8, 9] else drawLine(False)
    drawLine(True) if d in [0, 2, 3, 5, 6, 7, 8, 9] else drawLine(False)
    drawLine(True) if d in [0, 1, 2, 3, 4, 7, 8, 9] else drawLine(False)
    #     这时指针指向左，调整指向右
    turtle.left(180)
    turtle.up()
    turtle.fd(20)


# 遍历日期里每一个数字
def drawDate(date):
    for i in date:
        drawDigit(int(i))


# 自定义 笔 画布 时间
def main():
    turtle.setup(800, 500)
    turtle.penup()
    turtle.fd(-300)
    turtle.pensize(5)
    turtle.pencolor("red")
    # 获取当前时间（年月日）
    drawDate(time.strftime('%Y%m%d', time.gmtime()))


main()
